<!-- 问题文章写回答的 组件 -->
<template>
  <div id="articleWriteAnswer">
    <!-- 用户信息框 -->
    <div class="user_information_box">你的回答</div>
    <!-- 内容功能选择框 -->
    <!-- 输入框 -->
    <textarea class="write_textarea" v-model="contentData" placeholder="写回答..."></textarea>
    <!-- 底部提交框 -->
    <div class="function_down_box">
      <div class="btn_submit" @click="submitData">提交答案</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'articleWriteAnswer',
  components: {
  },
  props: ['questionId', 'ids'],
  data () {
    return {
      contentData: ''
    }
  },
  computed: {
  },
  methods: {
    submitData () {
      if (this.contentData.length === 0) {
        this.$Message.error('回答内容不可为空!')
      } else {
        // 传问题id、电话、内容 添加回答
        this.axios.get('/api/insertAnswer', {
          params: {
            phone: sessionStorage.getItem('phone'),
            question_id: this.questionId,
            content: this.contentData
          }
        })
          .then((response) => {
            this.$Message.success('成功!')
            // window.location.href = 'http://localhost:8081/articlePage/' + this.ids
            this.$router.push({path: '/articlePage/' + this.ids})
          })
          .catch((error) => {
            this.$Notice.error({
              title: '通知',
              desc: '接口，异常！'
            })
            console.info(error)
          })
      }
    }
  }
}
</script>

<style scoped>
  @import '../../../../../static/css/article/ArticleWriteAnswer.css';
</style>
